Flash Storage Device and Data Access Method of Flash Memory

ABSTRACT

The invention provides a data access method of a flash memory. First, a write command, a write address, and target data are received from a host. A target block corresponding to the write address is then determined from the flash memory. Whether a storage space corresponding to the write address in the target block has stored data therein is then determined When the storage space of the target block does not have stored data therein, the target data is written into the storage space of the target block. When the storage space of the target block does have stored data therein, whether a child block mapped to the target block exists in the flash memory is determined. When the child block exists in the flash memory, the target data is written into the child block.

CROSS REFERENCE TO RELATED APPLICATIONS

This Application claims priority of Taiwan Patent Application No.099101462, filed on Jan. 20, 2010, the entirety of which is incorporatedby reference herein.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention relates to memories, and more particularly to flashmemories.

2. Description of the Related Art

A flash memory comprises a plurality of blocks. Each block comprises aplurality of pages for data storage. When the flash memory receives awrite command from a controller, the flash memory must write receiveddata to at least one block thereof according to a write address. Whenthe flash memory receives a read command from the controller, the flashmemory must read data from at least one block thereof according to aread address.

When a page of a flash memory stores data, the page cannot be writtenwith new update data before the original data stored in the page iserased. Because a flash memory erases data in a unit of a block, thedata stored in all pages of a block must be erased together. Thus,erasing data from a block requires a long time period, and a controllercannot erase data from a flash memory with a high frequency.

When a host sends a write command to a controller to write new data to awrite address, if the pages of a target block corresponding to the writeaddress store original data, the controller cannot directly write thenew data to the pages of the target block. The controller, however, mustexecute the write command received from the host. The controllertherefore obtains a spare block from the flash memory to store the newdata. Because the new data stored in the spare block is mapped to thewrite address as the original data stored in the target block, there isa mapping relationship between the target block and the spare block. Thetarget block is therefore referred to as a mother block, and the spareblock is therefore referred to as a child block mapped to the motherblock for storing update data for the mother block.

Referring to FIG. 1, a mother block 102 and a child block 104 of aconventional mapping relationship is shown. The mother block 102comprise pages mapped to a logical address range of 0˜1000 and hasoriginal data A₀, B₀, C₀, and D₀ stored therein. When a host sends afirst write command to a controller to request the controller to writeupdate data B₁ to the address range 400˜600, the space corresponding tothe address range 400˜600 in the mother block 102 has stored originaldata B₀ and cannot store the update data B₁. The controller then selectsa spare block from the flash memory as the child block 104 mapped to themother block 102, copies the data A₀ corresponding to an address range0˜400 to the address range 0˜400 of the child block 104, and writes theupdate data B₁ to the address range 400˜600 of the child block 104.Similarly, if the host sends a second write command to the controller torequest the controller to write update data C₁ to an address range601˜700, because the space corresponding to the address range 601˜700 inthe mother block 102 has stored original data C₀, the controllerdirectly writes the update data C₁ to the address range 601˜700 of thechild block 104.

If the host sends a third write command to the controller to request thecontroller to write new data to an address range 0˜700, because thespace corresponding to the address range 0˜700 in the child block 105has stored data A₀ and update data B₁ and C₁, the controller cannotwrite the new data to the child block 104 to execute the third writecommand of the host. Thus, a data access method of a flash memory isrequired to solve the aforementioned problem.

BRIEF SUMMARY OF THE INVENTION

The invention provides a data access method of a flash memory. First, awrite command, a write address, and target data are received from ahost. A target block corresponding to the write address is thendetermined from the flash memory. Whether a storage space correspondingto the write address in the target block has stored data therein is thendetermined. When the storage space of the target block does not havestored data therein, the target data is written into the storage spaceof the target block. When the storage space of the target block doeshave stored data therein, whether a child block mapped to the targetblock exists in the flash memory is determined. When the child blockexists in the flash memory, whether the write address follows a lastaddress with stored data in the child block is determined When the writeaddress follows the last address, the target data is written into thechild block. When the write address does not follow the last address,whether a file allocation table (FAT) block mapped to the target blockexists in the flash memory is determined. When the FAT block exists inthe flash memory, the target data is written to the FAT block.

The invention also provides a flash storage device. In one embodiment,the flash storage device comprises a flash memory and a controller. Theflash memory comprises a plurality of blocks for data storage. Thecontroller receives a write command, a write address, and target datafrom a host, determines a target block corresponding to the writeaddress from the flash memory, checks whether a storage spacecorresponding to the write address in the target block has stored datatherein, writes the target data into the storage space of the targetblock when the storage space of the target block does not have storeddata therein, checks whether a child block mapped to the target blockexists in the flash memory when the storage space of the target blockdoes have stored data therein, checks whether the write address followsa last address with stored data in the child block when the child blockexists in the flash memory, writes the target data into the child blockwhen the write address follows the last address, checks whether a fileallocation table (FAT) block mapped to the target block exists in theflash memory when the write address does not follow the last address,and writes the target data to the FAT block when the FAT block exists inthe flash memory.

A detailed description is given in the following embodiments withreference to the accompanying drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention can be more fully understood by reading the subsequentdetailed description and examples with references made to theaccompanying drawings, wherein:

FIG. 1 shows a mother block and a child block of a conventional mappingrelationship;

FIG. 2 is a block diagram of a data storage system according to theinvention;

FIG. 3 is a flowchart of a data access method of a flash memoryaccording to the invention;

FIG. 4A is an embodiment of a series of write commands sent from a hostto a flash storage device;

FIG. 4B is a schematic diagram of a mother block corresponding to theaddresses of the write commands shown in FIG. 4A and a child block andan FAT block mapped to the mother block.

FIG. 5 is an embodiment of an update address table stored in an FATblock according to the invention; and

FIG. 6 is a flowchart of a data read method of a flash memory accordingto the invention.

DETAILED DESCRIPTION OF THE INVENTION

The following description is of the best-contemplated mode of carryingout the invention. This description is made for the purpose ofillustrating the general principles of the invention and should not betaken in a limiting sense. The scope of the invention is best determinedby reference to the appended claims.

Referring to FIG. 2, a block diagram of a data storage system 200according to the invention is shown. The data storage system 200comprises a host 202 and a flash storage device 204. The flash storagedevice 204 stores data for the host 202. In one embodiment, the flashstorage device 204 comprises a controller 212 and a flash memory 214.The flash memory 214 comprises a plurality of blocks. Each blockcomprises a plurality of pages for data storage. When the host 202 sendsa write command to the flash storage device 204, the controller 212writes data to the flash memory 214 according to the write command. Whenthe host 202 sends a read command to the flash storage device 204, thecontroller 212 read data from the flash memory 214 according to the readcommand.

When an address range of a target block of the flash memory 214 hasstored data, and the host 202 requests the flash storage device 204 towrite update data to the address range, the controller 212 cannotdirectly write the update data to the original address range of thetarget block of the flash memory 214. The controller 212 thereforeselects a spare block from the flash memory 214 as a child blockcorresponding to the target block to store the update data. The targetblock is referred to as a mother block in reference to the child block.When the host 202 requests the flash storage device 204 to write newupdate data to the address range again, the controller 212 cannotdirectly write the new update data to the target block or the childblock of the flash memory 214.

The controller 212 then selects a spare block from the flash memory 214as a file allocation table (FAT) block corresponding to the targetblock, and then writes the new update data to the FAT block. As shown inFIG. 2, the mother block 221, the child block 231, and the FAT block 241correspond to a single logical address range, and the mother block 22K,the child block 23K, and the FAT block 24K correspond to another logicaladdress range. An FAT block has a different data storage format fromthat of the child block. The child block stores update data withcontinuous addresses, and the FAT block stores update data ofdiscontinuous addresses. The child block cannot store two update datasegments with the same addresses, but the FAT block can store more thantwo update data segments with the same addresses. The data storageformat of the FAT block is further illustrated in detail with FIGS. 4A,4B, and 5.

Referring to FIG. 3, a flowchart of a data access method 300 of a flashmemory according to the invention is shown. The controller 212 executeswrite commands received from the host 202 according to the method 300.First, the controller 212 receives a write command, a write address, andtarget data from the host 202 (step 302). The controller 212 thendetermines a target block corresponding to the write address from aplurality of blocks of the flash memory 214 (step 304). The controller212 then determines whether a storage space corresponding to the writeaddress in the target block has stored data therein (step 306). If not,the controller 212 directly writes the target data to the storage spaceof the target block (step 308).

If the storage space corresponding to the write address in the targetblock stores data (step 306), the controller 212 cannot write the targetdata to the storage space of the target block. The controller 212 thendetermines whether a child block mapped to the target block exists inthe flash memory (step 310). If not, the controller 212 selects a spareblock from the flash memory as a child block corresponding to the targetblock (step 312), and writes the target data to the child block (step314). On the contrary, if the child block mapped to the target blockexists in the flash memory (step 310), the controller 212 determineswhether the write address of the target data follows a last address forstoring data in the child block (step 316).

If the write address of the target data follows a last address forstoring data in the child block (step 316), the controller 212 directlywrites the target data to the child block (step 314). After the targetdata is written to the child block, the controller 212 furtherdetermines whether an FAT block mapped to the target block exists in theflash memory 204 (step 318). If the FAT block exists and the FAT blockhas stored update data corresponding to the write address (step 318),the controller 212 further erases information about the write addressand the update data from an update address table stored in the FAT block(step 320).

If the write address of the target data does not follow the last addressfor storing data in the child block (step 316), the controller 212further determines whether an FAT block mapped to the target blockexists in the flash memory 204 (step 322). If so, the controller 212directly writes the target data to the FAT block (step 324). If not, thecontroller 212 selects a spare block from the flash memory 204 as an FATblock mapped to the target block (step 326), and writes the target datato the FAT block (step 328). After the controller 212 writes the targetdata to the FAT block (steps 324, 328), the controller 212 also writesan update address table to the FAT block, wherein the update addresstable records a mapping relationship between an original physicaladdress of an original data stored in the target block and an updatephysical address of the target data stored in the FAT block, and boththe original data and the target data logically correspond to the writeaddress.

The data access method 300 can be further illustrated with embodimentsof FIGS. 4A and 4B. Referring to FIG. 4A, an embodiment of a series ofwrite commands sent from the host 202 to the flash storage device 204 isshown. Referring to FIG. 4B, a schematic diagram of a mother block 402corresponding to the addresses of the write commands shown in FIG. 4Aand a child block 404 and an FAT block 406 mapped to the mother block402 is shown. The controller 212 first receives a write command 1 fromthe host 202, wherein the write command 1 requests the controller 212 towrite update data H to an address range 101˜200 of the flash memory 214.Assume that the mother block 402 has original data stored therein withan address range of 0˜1000. The address range of the write command 1therefore corresponds to the mother block 402. Because the address range101˜200 of the mother block 402 has original data stored therein, thecontroller 402 cannot directly write the update data H of the writecommand 1 to the mother block 402.

The mother block 402 initially does not have a corresponding child blockand a corresponding FAT block. The controller 212 therefore selects aspare block from the flash memory 204 as the child block 404 mapped tothe mother block 402, copies original data with an address range 0˜100to the child block 404, and then writes the update data H of the writecommand 1 to the address range 101˜200 of the child block 404. and thenthe host 202 sends a write command 2 to the controller 212 to requestthe controller 212 to write update data I to the address range 201˜300.Because the address range 201˜300 of the mother block 402 has originaldata stored therein, the controller 212 cannot directly write the updatedata Ito the mother block 402. Because the address range 201˜300 followsa last address 100 for storing data in the child block 404, thecontroller 212 writes the update data I to the address range 201˜300 ofthe child block 404.

The host 202 then sends a write command 3 to the controller 212 torequest the controller 212 to write update data J to an address range251˜400, wherein the update data J is divided into update data J₁ withan address range 251˜300 and update data J₂ with an address range301˜400. Because the address range 301˜400 of the update data J₂ followsthe last address 300 for storing data in the child block 404, thecontroller 212 writes the update data J₂ to the address range 301˜400 ofthe child block 404. Because the address range 251˜300 of the updatedata J₁ overlaps with the address range of the update data I stored inthe child block 404, the controller 212 cannot write the update data J₁into the child block 404. The controller 212 therefore selects a spareblock from the flash memory 214 as an FAT block 406 mapped to the motherblock 402, writes update data J₁ into the FAT block 406, and writes anupdate address table I comprising information about the update data J₁into the FAT block 406.

The host 202 then sends a write command 4 to the controller 212 torequest the controller 212 to write the update data K to an addressrange 451˜500. Because the address range 451˜500 of the update data Kdoes not follow a last address 400 of the child block 404, thecontroller 212 does not write the update data K to the child block 404.Instead, the controller 212 writes the update data K to the FAT block406, and writes an update address table II comprising information aboutthe update data K into the FAT block 406. The host 202 then sends awrite command 5 to the controller 212 to request the controller 212 towrite the update data M to an address range 401˜500. Because the addressrange 401˜500 of the update data M follows a last address 400 of thechild block 404, the controller 212 directly write the update data M tothe child block 404. Because the update data K stored in the FAT blockhas an address range 451˜500 overlapping with the address range 401˜500of the update data M, the controller 212 erases information about theupdate data K from the update address table II to obtain an updateaddress table III, and writes the update address table III into the FATblock 406.

Referring to FIG. 5, an embodiment of an update address table 500 storedin a FAT block according to the invention is shown. The update addresstable stores a mapping relationship between physical addresses oforiginal data stored in a mother block and physical addresses of allupdate data stored in the FAT block, wherein the update data is mappedto the original data. In one embodiment, the update address table 500comprises two columns which are an original data address column and anupdate data address column. Assume that the FAT block storing the updateaddress table 500 is mapped to a mother block with an address range0˜1000. The original data address column of the update address table 500therefore records an address range 0˜1000. The update data addresscolumn records the physical addresses of the update data mapped to thecorresponding physical addresses of the original data. If the FAT blockstores update data with a physical address Y, and the update data ismapped to the original data with the physical address X in the motherblock, the original data address column of the update address table 500records the address X of the original data in the mother block, and thecorresponding update data address column of the update address table 500records the address Y of the update data in the FAT block. For example,the original data with addresses 0˜2 does not have corresponding updatedata in the FAT block, and the update data address column of the updateaddress table 500 does not record addresses of the update datacorresponding to the original data addresses 0˜2. The original data withaddresses 998 and 999 has corresponding update data with addresses 353and 354 in the FAT block, and the update data address column of theupdate address table 500 records addresses 353 and 354 of the updatedata corresponding to the original data addresses 998 and 999. Thecontroller 22 can therefore determine all physical addresses of theupdate data mapped to the original data of the mother block according tothe update address table 500.

Referring to FIG. 6, a flowchart of a data read method 600 of a flashmemory according to the invention is shown. The controller 212 executesread commands received from the host 202 according to the method 600.First, the controller 212 receives a read command and a read addressfrom the host 202 (step 602). The controller 212 then determines atarget block corresponding to the read address from the flash memory 214(step 604). The controller 212 then determines whether an FAT blockmapped to the target block exists in the flash memory 214 (step 606). Ifso, the controller 212 determines whether the FAT block has update dataof the read address stored therein (step 612). If so, the controller 212reads the update data corresponding to the read address from the FATblock (step 614).

If the FAT block does not have update data stored therein correspondingto the read address (step 612), or the flash memory 214 does notcomprise an FAT block mapped to the target block (step 606), thecontroller 212 further determines whether a child block mapped to thetarget block exists in the flash memory 214 (step 608). If so, thecontroller 212 further determines whether the child block has updatedata of the read address stored therein (step 616). If so, thecontroller 212 reads the update data corresponding to the read addressfrom the child block (step 618). If the child block does not have updatedata corresponding to the read address stored therein (step 616), or theflash memory 214 does not comprise a child block mapped to the targetblock, the controller 212 directly reads data corresponding to the readaddress from the target block (step 610).

While the invention has been described by way of example and in terms ofpreferred embodiment, it is to be understood that the invention is notlimited thereto. To the contrary, it is intended to cover variousmodifications and similar arrangements (as would be apparent to thoseskilled in the art). Therefore, the scope of the appended claims shouldbe accorded the broadest interpretation so as to encompass all suchmodifications and similar arrangements.

1. A data access method of a flash memory, comprising: receiving a writecommand, a write address, and target data from a host; determining atarget block corresponding to the write address from the flash memory;checking whether a storage space corresponding to the write address inthe target block has stored data therein; when the storage space of thetarget block does not have stored data therein, writing the target datainto the storage space of the target block; when the storage space ofthe target block does have stored data therein, checking whether a childblock mapped to the target block exists in the flash memory; when thechild block exists in the flash memory, checking whether the writeaddress follows a last address with stored data in the child block; whenthe write address follows the last address, writing the target data intothe child block; when the write address does not follow the lastaddress, checking whether a file allocation table (FAT) block mapped tothe target block exists in the flash memory; and when the FAT blockexists in the flash memory, writing the target data to the FAT block. 2.The data access method as claimed in claim 1, wherein the method furthercomprises: when the child block does not exist in the flash memory,selecting a spare block from the flash memory as the child block mappedto the target block; and writing the target data to the child block. 3.The data access method as claimed in claim 1, wherein the method furthercomprises: when the FAT block does not exist in the flash memory,selecting a spare block from the flash memory as the FAT block mapped tothe target block; and writing the target data into the FAT block.
 4. Thedata access method as claimed in claim 1, wherein writing of the targetdata to the FAT block comprises: writing the target data to the FATblock; and writing an update address table into the FAT block, whereinthe update address table records a mapping relationship between anoriginal physical address of an original data stored in the target blockand an update physical address of the target data stored in the FATblock, and both the original data and the target data logicallycorrespond to the write address.
 5. The data access method as claimed inclaim 1, wherein writing of the target data to the child blockcomprises: checking whether the FAT block mapped to the target blockexists in the flash memory; checking whether an update data logicallycorresponding to the write address is stored in the FAT block; when theFAT block exists in the flash memory and the FAT block has the updatedata stored therein, erasing information about the write address from anupdate address table stored in the FAT block; and writing the targetdata to a target storage space in the child block, wherein the updateaddress table records a mapping relationship between an originalphysical address of an original data stored in the target block and anupdate physical address of the update data stored in the FAT block, andboth the original data and the update data logically correspond to thewrite address.
 6. The data access method as claimed in claim 5, whereinthe starting address of the target storage space follows a last addressfor storing data in the child block.
 7. The data access method asclaimed in claim 1, wherein the method further comprises: receiving aread command and a read address from the host; determining a read targetblock corresponding to the read address; checking whether a read FATblock mapped to the read address exists in the flash memory; when theread FAT block exists, checking whether first update data correspondingto the read address is stored in the read FAT block; and when the firstupdate data is stored in the read FAT block, reading the first updatedata from the read FAT block.
 8. The data access method as claimed inclaim 7, wherein the method further comprises: when the read FAT blockdoes not exist, or when the first update data is not stored in the readFAT block, checking whether a read child block mapped to the read targetblock exists in the flash memory; and when the read child block does notexist, reading second update data from the read target block accordingto the read address.
 9. The data access method as claimed in claim 8,wherein the method further comprises: when the read child block exists,checking whether third update data corresponding to the read address isstored in the read child block; when third update data is stored in theread child block, reading the third update data from the read childblock; and when the third update data is not stored in the read childblock, reading the second update data from the read target blockaccording to the read address.
 10. A flash storage device, comprising: aflash memory, comprising a plurality of blocks for data storage; acontroller, receiving a write command, a write address, and target datafrom a host, determining a target block corresponding to the writeaddress from the flash memory, checking whether a storage spacecorresponding to the write address in the target block has stored datatherein, writing the target data into the storage space of the targetblock when the storage space of the target block does not have storeddata therein, checking whether a child block mapped to the target blockexists in the flash memory when the storage space of the target blockdoes have stored data therein, checking whether the write addressfollows a last address with stored data in the child block when thechild block exists in the flash memory, writing the target data into thechild block when the write address follows the last address, checkingwhether a file allocation table (FAT) block mapped to the target blockexists in the flash memory when the write address does not follow thelast address, and writing the target data to the FAT block when the FATblock exists in the flash memory.
 11. The flash storage device asclaimed in claim 10, wherein when the child block does not exist in theflash memory, the controller selects a spare block from the flash memoryas the child block mapped to the target block, and writes the targetdata to the child block.
 12. The flash storage device as claimed inclaim 10, wherein when the FAT block does not exist in the flash memory,the controller selects a spare block from the flash memory as the FATblock mapped to the target block, and writes the target data into theFAT block.
 13. The flash storage device as claimed in claim 10, whereinwhen the controller writes the target data to the FAT block, thecontroller also writes an update address table into the FAT block,wherein the update address table records a mapping relationship betweenan original physical address of an original data stored in the targetblock and an update physical address of the target data stored in theFAT block, and both the original data and the target data logicallycorrespond to the write address.
 14. The flash storage device as claimedin claim 10, wherein when the controller writes the target data to thechild block, the controller checks whether the FAT block mapped to thetarget block exists in the flash memory, checks whether an update datalogically corresponding to the write address is stored in the FAT block,erases information about the write address from an update address tablestored in the FAT block if the FAT block exists in the flash memory andthe FAT block has the update data stored therein, and writes the targetdata to a target storage space in the child block, wherein the updateaddress table records a mapping relationship between an originalphysical address of an original data stored in the target block and anupdate physical address of the update data stored in the FAT block, andboth the original data and the update data logically correspond to thewrite address.
 15. The flash storage device as claimed in claim 14,wherein the starting address of the target storage space follows a lastaddress for storing data in the child block.
 16. The flash storagedevice as claimed in claim 10, wherein the controller further receives aread command and a read address from the host, determines a read targetblock corresponding to the read address, checks whether a read FAT blockmapped to the read address exists in the flash memory, checks whetherfirst update data corresponding to the read address is stored in theread FAT block when the read FAT block exists, and reads the firstupdate data from the read FAT block when the first update data is storedin the read FAT block.
 17. The flash storage device as claimed in claim16, wherein when the read FAT block does not exist, or when the firstupdate data is not stored in the read FAT block, the controller checkswhether a read child block mapped to the read target block exists in theflash memory, and reads second update data from the read target blockaccording to the read address if the read child block does not exist.18. The flash storage device as claimed in claim 17, wherein when theread child block exists, the controller checks whether third update datacorresponding to the read address is stored in the read child block,reads the third update data from the read child block if the read childblock stores the third update data, and reads the second update datafrom the read target block according to the read address if the thirdupdate data is not stored in the read child block.